package com.hly.poitool.byteUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author : Jack Hao
 * @Date : 2022/3/29 16:03
 * @description :
 */
public class ByteUtil {


    /**
     * 获取文件的 byte 的数组
     *
     * @param filePath
     * @return
     */
    public static byte[] getFileByteArray(String filePath) {
        ReentrantLock lock = new ReentrantLock();
        byte[] tByte = null;
        try {
            lock.lock();
            FileInputStream redTemplateInputStream = new FileInputStream(filePath);
            tByte = new byte[redTemplateInputStream.available()];
            redTemplateInputStream.read(tByte);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
        return tByte;
    }

}
